package com.zdp.util;

public class ListNode {
    public int val;
    public ListNode next;
    public ListNode() {}
    public ListNode(int val) { this.val = val; }
    public ListNode(int val, ListNode next) { this.val = val; this.next = next; }

    // 创建多个
    public static ListNode createListNode(int...val){
        ListNode head = new ListNode();
        head.next = null;
        ListNode pp = head;
        for(int t:val){
            ListNode p = new ListNode();
            p.val = t;
            p.next = head.next;
            head.next = p;
            head = head.next;
        }
        return pp.next;
    }

    public void soutList(){
       staticSoutList(this);
    }
    public static void staticSoutList(ListNode head){
        ListNode p = head;
        int n=0;
        while(p!=null){
            if(n==0){
                n++;
                System.out.print(p.val);
            }else {
                System.out.print("-->" + p.val);
            }
            p = p.next;
        }
    }
}
